import fetch from "@/utils/http";
import type { UpdateInfo, User } from "./userDetail";
import { queryToString } from "@/utils/utils";
export interface Info {
  username: string;
}

/** 登录 */
export interface LoginParams {
  username: string;
  password: string;
}
export const getLogin = (data?: LoginParams) => {
  return fetch<{ token: string }>("/login", "MANGMENT", {
    method: "post",
    body: JSON.stringify(data)
  });
};
/**
 * 获取用户信息
 */
export const getUserInfo = () => {
  return fetch<User>("/system/user/profile", "MANGMENT", {
    method: "get"
  });
};

/**
 * 更改密码
 */
export const operatorChangePassword = (data: {
  oldPassword: string;
  newPassword: string;
}) => {
  return fetch(
    `/system/user/profile/updatePwd?${queryToString(data)}`,
    "MANGMENT",
    {
      method: "put"
    }
  );
};
/**
 * 修改个人信息
 */
export const updateSingleInfo = (data: UpdateInfo) => {
  return fetch("system/user/profile", "MANGMENT", {
    method: "put",
    body: JSON.stringify(data)
  });
};
